<template>
    <div>
        <div>
            供应商名称<el-select v-model="searchForm.providerId" placeholder="请输入供应商名称">
            <el-option
                    v-for="item in deptData"
                    :key="item.providerId"
                    :label="item.providerName"
                    :value="item.providerId">
            </el-option>
        </el-select>
            申请人<el-input v-model="searchForm.applyUserName" placeholder="请输入申请人" style="width: 100px;"></el-input>
            单据状态<el-select v-model="searchForm.status" placeholder="单据状态">
            <el-option
                    v-for="item in statusOptions"
                    :key="item.dictValue"
                    :label="item.dictLabel"
                    :value="item.dictValue">
            </el-option>
        </el-select>
            <el-button type="primary" @click="queryAll()">搜索</el-button>
            <el-button type="primary" @click="resetFormFiled()">重置</el-button>
        </div>
        <div>
            <el-button type="primary" style="float: left;" @click="handleToNewPurchase">新增采购</el-button>
            <el-button type="primary" style="float: left;" @click="addUser()">提交审核</el-button>
            <el-button type="primary" style="float: left;" @click="addUser1()">作废</el-button>
            <el-button type="primary" style="float: left;" @click="addUser2()">提交入库</el-button>
        </div>
        <el-table
                ref="multipleTable"
                :data="tableData"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange">
            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>
            <el-table-column label="单据ID" align="center" width="200" prop="purchaseId">
                <template slot-scope="scope">
<!--                    <router-link :to="'/views/stock/editPurchase/'+scope.row.purchaseId" class="link-type">-->
                        <router-link :to="{path:'/views/stock/editPurchase',query:{purchaseId:scope.row.purchaseId}}" class="link-type">
                        <span>{{ scope.row.purchaseId }}</span>
                    </router-link>
                </template>
            </el-table-column>
            <el-table-column prop="provider.providerName" label="供应商" width="200">
            </el-table-column>
            <el-table-column prop="purchaseTradeTotalAmount" label="采购批发总额" width="120">
            </el-table-column>
            <el-table-column prop="status" label="状态" width="120" :formatter="statusformat">
            </el-table-column>
            <el-table-column prop="applyUserName" label="申请人" width="120">
            </el-table-column>
            <el-table-column prop="storageOptUser" label="入库操作人" width="120">
            </el-table-column>
            <el-table-column prop="storageOptTime" label="入库时间" width="200">
            </el-table-column>
            <el-table-column prop="auditMsg" label="审核信息" width="120">
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间" width="200">
            </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page.current"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="page.seze"
                layout="total, sizes, prev, pager, next, jumper"
                :total="page.total">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        name: "Purchase",
        methods:{
            //重置
            resetFormFiled(){
                this.searchForm={};
                this.initTable();
            },
            //生产厂家下拉框
            providerName(){
                this.$axios.get("medicine/purchase/providerName").then(r=>{
                    this.deptData=r.data.t;
                    this.initTable();
                })
            },
            //提交入库
            addUser2(){
                this.$axios.post('medicine/purchase/modification2',this.multipleSelection[0]).then(r=>{
                    this.initTable();
                })
            },
            //作废
            addUser1(){
                this.$axios.post('medicine/purchase/modification1',this.multipleSelection[0]).then(r=>{
                    this.initTable();
                })
            },
            //提交审核
            addUser(){

                this.$axios.post('medicine/purchase/modification',this.multipleSelection[0]).then(r=>{
                    this.initTable();
                })
            },
            //新增采购
            handleToNewPurchase() {
                this.$router.replace('/views/stock/newPurchase')
            },
            //状态字典解析
            statusformat(row){
                let val=row.status ;
                return this.formatDict(this.statusOptions,val)
            },
            //状态
            initStatus(){
                this.$axios.get("system/api/dict/data/findByType/his_order_status").then(r=>{
                    this.statusOptions = r.data.t;
                })
            },
            //批量
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            //搜索
            queryAll(){
                this.page.current=1;
                this.initTable();

            },
            //分页
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.page.size=val;
                this.initTable();
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.page.current=val;
                this.initTable();
            },
            //刷新表格  //模糊查询
            initTable() {
                let search={...this.page,...this.searchForm};
                this.$axios.get('medicine/purchase/getAll/',{params:search}).then(r => {
                    this.tableData = r.data.t.records;
                    //刷新总条数
                    this.page.total=r.data.t.total;
                })
            }
        },
        data() {
            return {
                tableData: [],
                page:{
                    total:10,
                    current:1,
                    size:10
                },
                searchForm: {},
                deptData:[],
                multipleSelection: [],
                statusOptions:[],

            }
        },
        created() {
            this.initTable();
            this.initStatus();
            this.providerName();
        }
    }
</script>

<style scoped>

</style>


